package com.igeek.d0603;

import java.util.*;

/**
 * @Author: zhiyu
 * @Date:14:50
 * @DESC:
 */
public class Card implements Comparable<Card>{
    private String num;
    private String color;

    public Card(String num, String color) {
        this.num = num;
        this.color = color;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return Objects.equals(num, card.num) && Objects.equals(color, card.color);
    }

    @Override
    public int hashCode() {
        return Objects.hash(num, color);
    }

    public Card() {
    }

    @Override
    public String toString() {
        return color+" "+num;
    }

    public  ArrayList<Card> createCard(){
        String[] nums = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        String[] color = {"♠","♣","♥","♦"};
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < color.length; j++) {
                cards.add(new Card(nums[i],color[j]));
            }
        }
        cards.add(new Card("大王","red"));
        cards.add(new Card("小王","black"));
        return cards;
    }
    public ArrayList<Card> scrambleSorting(ArrayList<Card> cards){
        Collections.shuffle(cards);
        return cards;
    }
    public void licensing(ArrayList<Card> cards){
        List<Card> p1 = new ArrayList<>();
        List<Card> p2 = new ArrayList<>();
        List<Card> p3 = new ArrayList<>();
        for (int i = 0; i < cards.size();) {
            p1.add(cards.get(i));
            p2.add(cards.get(i+1));
            p3.add(cards.get(i+2));
            if ((i+2)==cards.size()-4){
                break;
            }
            i+=3;
        }
        System.out.println();
        if (p1.contains(new Card("大王","red"))){
            p1.add(cards.get(51));
            p1.add(cards.get(52));
            p1.add(cards.get(53));
        }else if (p2.contains(new Card("大王","red"))){
            p2.add(cards.get(51));
            p2.add(cards.get(52));
            p2.add(cards.get(53));
        }else if (p3.contains(new Card("大王","red"))){
            p3.add(cards.get(51));
            p3.add(cards.get(52));
            p3.add(cards.get(53));
        }else {
            System.out.println("大王在底牌中,请重新开始游戏");
        }
        Collections.sort(p1);
        Collections.sort(p2);
        Collections.sort(p3);
        System.out.println("第一个人 "+p1.size()+"=" + p1);
        System.out.println("第二个人 "+p2.size()+"=" + p2);
        System.out.println("第三个人 "+p3.size()+"=" + p3);
    }

    @Override
    public int compareTo(Card o) {
        return o.num.compareTo(this.getNum());
    }
}
